classdef sp_plot < hgsetget
    properties (SetObservable)
        marker
        markerfacecolor
        markeredgecolor
        markersize
        linestyle
        linewidth
        color
    end
    
    properties (Hidden, SetObservable)
        line_hand
    end
    
    methods
        function obj = sp_plot(varargin)
            if nargin==0
                obj.marker = 'o';
                obj.markerfacecolor='r';
                obj.markeredgecolor='r';
                obj.linestyle='None';
                obj.color='r';
                obj.linewidth=1;
                obj.markersize=5;
            end
            if nargin == 1
                objS=varargin{1};
                if isa(objS,'sp_plot')
                    
                end
                
                if isa(objS,'struct')
                    obj=sp_plot;
                    p=properties(obj);
                    f=fieldnames(objS);
                    for i=1:length(f)
                        if any(strcmp(f{i},p))
                            set(obj,f{i},objS.(f{i}))
                        end
                    end
                    return
                end
            end
            
            if nargin == 2
                obj=varargin{1};
                obj2=varargin{2};
                if isa(obj,'sp_plot') && isa(obj2,'struct')
                    p=properties(obj);
                    f=fieldnames(obj2);
                    for i=1:length(f)
                        if any(strcmp(f{i},p))
                            set(obj,f{i},obj2.(f{i}))
                        end
                    end 
                    return
                end
            end
            
            addlistener(obj,'line_hand','PostSet',@sp_plot.setPlot);
            p=properties(obj);
            for i=1:length(p)
                addlistener(obj,p{i},'PostSet',@sp_plot.propChange);
            end
            
        end
    end
    
    methods (Static)
        function setPlot(src,evnt)
            switch src.Name
                case 'line_hand'
                    evnt.AffectedObject
                    h=evnt.AffectedObject.line_hand;
                    p=properties(evnt.AffectedObject);
                    for i=1:length(p)
                        set(h,p{i},get(evnt.AffectedObject,p{i}))
                    end
            end
        end
        
        function propChange(src,evnt)
            h = evnt.AffectedObject.line_hand;
            if ishandle(h)
                set(h,src.Name,evnt.AffectedObject.(src.Name))
            end
        end
        
    end
                
       
end